﻿using B.S.Orders.Domain;
using B.S.Orders.ErrorCord;
using B.S.Orders.Read.Api.Application.Commands.OutsourcingCommand;
using MediatR;
using SqlSugar;

namespace B.S.Orders.Read.Api.Application.CommandsHander.OutsourcingCommandHandler
{
    public class GetBYIdOutsourcingCommandHandler : IRequestHandler<GetBYIdOutsourcingCommand, APIResult<List<Outsourcing>>>
    {
        private readonly ISqlSugarClient db;

        public GetBYIdOutsourcingCommandHandler(ISqlSugarClient db)
        {
            this.db = db;
        }

        public async Task<APIResult<List<Outsourcing>>> Handle(GetBYIdOutsourcingCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Outsourcing>> result = new APIResult<List<Outsourcing>>();
            result.Code = APIEnum.success;
            result.Msg = "查询成功";
            var list = await db.Queryable<Outsourcing>().Where(p => p.OutsourcingId == request.OutsourcingId).ToListAsync();

            result.Data = list;
            return await Task.FromResult(result);
        }
    }
}
